package com.rfchina.okr.xianren.controller.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.rfchina.okr.xianren.model.AppInfo;
import com.rfchina.okr.xianren.util.MyUtil;

public class ApiActionInterceptor implements Interceptor {

	private static Logger logger = LoggerFactory.getLogger(ApiActionInterceptor.class);

	public void intercept(Invocation inv) {

		Controller conn = inv.getController();
		String appid = conn.getPara("appid");
		String sign = conn.getPara("sign");
		Long time = conn.getParaToLong("time");

		if (StrKit.isBlank(sign)) {
			MyUtil.error(406, "sign为空");
		}
		
		if (time==null||time<=0) {
			MyUtil.error(407, "time为空,时间戳");
		}
		if (StrKit.isBlank(appid)) {
			MyUtil.error(408, "appid为空");
		}
		AppInfo app = AppInfo.dao.findById(appid);
		if (app == null) {
			MyUtil.error(409, "没有这个appid"+appid);
		}
		logger.info("appid:{}",appid);
		conn.setAttr("__appid", appid);
		inv.invoke();

	}

}
